<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');	 
session_start(); 
class Verifyfindpass extends CI_Controller {
     function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->load->model('Findpass_m');
        $this->load->library('email');
    
    }
    function index()
    {
        $config['protocol']    = 'smtp';
        $config['smtp_host']    = 'ssl://smtp.gmail.com';
        $config['smtp_port']    = '465';
        $config['smtp_timeout'] = '7';
        $config['smtp_user']    = 't06k53itjp@gmail.com';
        $config['smtp_pass']    = 'hedspit06';
        $config['charset']    = 'utf-8';
        $config['newline']    = "\r\n";
        $config['mailtype'] = 'text'; // or html
        $config['validation'] = TRUE; // bool whether to validate email or not      
        $this->email->initialize($config);
        //$this->email->set_newline("\r\n");
        $id=$this->input->post('txtID');
        $email_findpass = $this->input->post('txtEmail');
        //$session_data_mg = $this->session->userdata('login_id');
	//$id_mg = $session_data_mg['id_login'];
        
        if($this->Findpass_m->find_email_admin($id))
        {
        $query_admin=$this->Findpass_m->find_email_admin($id);
        foreach($query_admin as $row_admin)
        {
            $email_admin=$row_admin->email;
            $password_admin=$row_admin->password;
        }
        }
        else $email_admin="";
        if($this->Findpass_m->find_email_manager($id))
        {
            
        $query_manager=$this->Findpass_m->find_email_manager($id);
        foreach($query_manager as $row_manager)
        {
            $email_manager=$row_manager->email;
            echo $email_manager;
            $password_manager=$row_manager->password;
        }
        }
        else $email_manager="";
        if($this->Findpass_m->find_email_examiner($id))
        {
        $query_examiner=$this->Findpass_m->find_email_examiner($id);
        foreach($query_examiner as $row_examiner)
        {
            $email_examiner=$row_examiner->email;
            
            $password_examiner=$row_examiner->password;
        }
        }
        else $email_examiner="";
        if($this->Findpass_m->find_email_maker($id))
        {
        $query_maker=$this->Findpass_m->find_email_maker($id);
        foreach($query_maker as $row_maker)
        {
            $email_maker=$row_maker->email;
            echo $email_maker;
            $password_maker=$row_maker->password;
        }
        }
        else $email_maker="";
        if($email_admin==$email_findpass||$email_examiner==$email_findpass||$email_manager==$email_findpass||
                $email_maker==$email_findpass) 
        {

            $Subject="パースワードの再設定";        
            $this->email->from('t06k53itjp@gmail.com', 'K53 HEDSPI T06');
            $this->email->subject($Subject);
            if($email_admin==$email_findpass)
            {
            $this->email->to($email_admin);
            $Content="あなたのパースワード:".$password_admin;
            }
            else if($email_manager==$email_findpass)
            {
            $this->email->to($email_manager);
            $Content="あなたのパースワード:".$password_manager; 
            }
            else if($email_examiner==$email_findpass)
            {
            $this->email->to($email_examiner);
            $Content="あなたのパースワード:".$password_examiner; 
            }
            else if($email_maker==$email_findpass)
            {
            $this->email->to($email_maker);
            $Content="あなたのパースワード:".$password_maker; 
            }
            $this->email->message($Content);
            if($this->email->send())
            {
                //echo $this->email->print_debugger();
                $data['wait']="パースワードを再確認するために、メールを見てお願い致します!";
                $this->load->view('login/login_v',$data,'refresh');
            }
            else
            {
                $data['send_error']="error send mail!";
                $this->load->view('findpass/findpass_v',$data,'refresh');
            }
        }
        else
        {
            $data['not_email']="メールのアドレス又はIDが違い!";
            $this->load->view('findpass/findpass_v',$data,'refresh');
        }
    }
}
    
?>